import React from 'react'
import NavHeader from '../../components/NavHeader'
import HouseItem from '../../components/HouseItem'
import request from '../../utils/request'

class Favorate extends React.Component   {
  state = {
    list: []
  }
  componentDidMount () {
    this.getList()
  }
  async getList () {
    const { data: res } = await request('/user/favorites', 'GET')
    if (res.status === 200) {
      this.setState(_ => {
        return {
          list: res.body
        }
      })
    }
  }
   rednerList () {
    return (
     this.state.list.map(x => {
        return ( <HouseItem {...x} key={x.title}/> )
      })
    )
  }
  render () {
    const { list } = this.state
    return (
      <>
      <NavHeader >收藏列表</NavHeader>
      { list.length > 0 ? this.rednerList() : ''}
      </>
      
    )
  }
}
export default Favorate